package com.hzzc.core.controller.back;

import com.hzzc.BizException;
import com.hzzc.Result;
import com.hzzc.core.model.SSOApplication;
import com.hzzc.core.service.ApplicationService;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/back")
public class BackApplicationController {

    @Autowired
    private ApplicationService applicationService;

    @GetMapping("/apps")
    public Result<List<SSOApplication>> apps() {
        return Result.success(applicationService.applicationList(), "");
    }

    @PostMapping("/app")
    public Result<List<SSOApplication>> addApp(@RequestBody ApplicationBean applicationBean) throws BizException {
        applicationService.addApplication(applicationBean.name, applicationBean.code, applicationBean.msg);
        return Result.success(applicationService.applicationList(), "");
    }

    @DeleteMapping("/delApp")
    public Result<List<SSOApplication>> delApp(@RequestParam("appId") Long applicationId) throws BizException {
        applicationService.delApplication(applicationId);
        return Result.success(applicationService.applicationList(), "");
    }

    @Data
    static class ApplicationBean {

        private String code;

        private String name;

        private String msg;

    }

}
